package cn.mcch.investigator.service;

import android.app.Service;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Handler;
import android.os.IBinder;
import android.os.Process;

import cn.mcch.investigator.utils.L;

/**
 * @author Javen
 *         开启一个服务开监听数据库
 */
public class SmsService extends Service {

    private SmsObserver mObserver;

    private SmsHandler handler;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        handler = new SmsHandler(this);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        L.e("开始监听短信变化");
        ContentResolver resolver = getContentResolver();
        mObserver = new SmsObserver(handler, resolver);
        resolver.registerContentObserver(Uri.parse("content://sms"), true, mObserver);
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
//        this.getContentResolver().unregisterContentObserver(mObserver);
//        Process.killProcess(Process.myPid());
    }
}